<template>
  <div>
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item> <i class="el-icon-shopping-bag-2"></i> 用户管理 </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="container">
      <div class="handle-box">
        <el-date-picker class="mr10" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd"
                        v-model="query.time">
        </el-date-picker>
        <el-select class="mr10" v-model="query.status" placeholder="请选择账号状态">
          <el-option label="全部账号" value=""></el-option>
          <el-option label="启用账号" value="1"></el-option>
          <el-option label="停用账号" value="0"></el-option>
        </el-select>
        <el-input placeholder="请输入用户名/手机号/公司名称/联系人查询" v-model="query.souVal" class="handle-input mr10"></el-input>
        <el-button type="primary" icon="el-icon-search" @click="souClick">搜索</el-button>
      </div>
      <el-table v-loading="loading" :data="tableData" border class="table" style="width: 100%" ref="multipleTable"
                header-cell-class-name="table-header" @selection-change="SelectionChange">
        <el-table-column type="selection" width="55" align="center"></el-table-column>
        <el-table-column type="index" :index="tableIndex" label="序号" width="55" align="center"></el-table-column>
        <el-table-column prop="name" label="用户名" width="150">
          <template slot-scope="scope">
            <el-button type="text">{{scope.row.userName}}</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="phone" label="手机号" width="150"></el-table-column>
        <el-table-column prop="companyName" label="公司名称" width="280"></el-table-column>
        <el-table-column prop="contactsName" label="联系人姓名"></el-table-column>
        <el-table-column prop="createTime" label="创建时间" width="210"></el-table-column>
        <el-table-column fixed="right" prop="mobileCreate" label="账号状态" width="150">
          <template slot-scope="scope">
            <el-switch v-model="scope.row.status" active-value="1" active-text="启用" inactive-text="停用" inactive-value="0"
                       @change="statusChange(scope.row)">
            </el-switch>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination background layout="total, prev, pager, next" :current-page="query.page" :page-size="query.limit" :total="page.totalCount"
                       :pager-count="5" @current-change="PageChange" @prev-click="PageChange" @next-click="PageChange"></el-pagination>
      </div>
    </div>

  </div>
</template>

<script>
import { jdUserListList, jdUserListisOpen } from '../../../api/index';

export default {
  data() {
    return {
      loading: false,
      query: {
        page: 1,
        limit: 10,
        time: [],
        souVal: '',
        status: '',
      },
      tableData: [],
      page: {
        totalCount: 100
      },
      touupdateImgLoad: false,
    };
  },

  created() {
    this.getListData();
  },
  methods: {
    //列表信息
    getListData() {
      this.loading = true;
      let query = {
        startTime: this.query.time ? this.query.time[0] : '',
        endTime: this.query.time ? this.query.time[1] : '',
        kw: this.query.souVal,
        limit: this.query.limit,
        page: this.query.page,
        status: this.query.status
      };
      jdUserListList(query).then((res) => {
        this.loading = false;
        if (res.code === 0) {
          res.recordList.map(item => {
            item.status = String(item.status);
          })
          this.tableData = res.recordList;
          this.page.totalCount = res.totalCount;
        } else {
          this.$message(res.msg);
        }
      });
    },
    //序号
    tableIndex(index) {
      return (this.query.page - 1) * this.query.limit + index + 1;
    },
    //搜索
    souClick() {
      this.query.page = 1;
      this.getListData();
    },
    //翻页
    PageChange(num) {
      this.query.page = num;
      this.getListData();
    },
    //选中
    SelectionChange() { },
    //账号状态操作
    statusChange(item) {
      console.log(item);
      jdUserListisOpen({
        userId: item.uId,
        status: item.status
      }).then(res => {
        if (res.code == 0) {
          this.$message.success("操作成功");
          this.souClick();
        } else {
          this.$message(res.msg);
        }
      })
    },
  }
};
</script>

<style scoped>
/deep/ :focus {
    outline: 0;
}
.handle-input {
    width: 300px;
    display: inline-block;
}
.nameDrawer {
    padding: 30px;
}
.elSelect {
    width: 100%;
}
.upload-demo {
    height: 32px;
}
.heng-border {
    height: 0.5px;
    margin-bottom: 30px;
}

/* 截图 */
.cropper-content .cropper {
    width: auto;
    height: 300px;
}
.refund-list {
    margin-bottom: 10px;
}
.payment_type {
    padding: 10px 0;
}
</style>
